using KinonekoSoftware.CodariaDB;
using KinonekoSoftware.CodariaDB.Documents.Index;
using KinonekoSoftware.CodariaDB.Documents.TemplateContents.Abilities;
using KinonekoSoftware.CodariaDB.Documents.Theories.Elements;
using KinonekoSoftware.CodariaDB.Documents.Theories.Rarities;
using KinonekoSoftware.CodariaDB.Runtimes;
using Microsoft.Xaml.Behaviors;

namespace KinonekoSoftware.Studio.Services.Renderers
{

    public partial class AbilityRenderer : UserControl
    {
        public AbilityRenderer()
        {
            InitializeComponent();
        }

        // Vocabularies List
        // Intro string
        // Keywords 
        // RarityBackground
        // RarityLevel int


        public static readonly DependencyProperty ElementImageIDProperty =
            DependencyProperty.Register(
                                        nameof(ElementImageID),
                                        typeof(string),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(string)));


        public static readonly DependencyProperty EnableElementProperty =
            DependencyProperty.Register(
                                        nameof(EnableElement),
                                        typeof(bool),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(Boxing.False));


        public static readonly DependencyProperty EnableLeftTopOverlayProperty =
            DependencyProperty.Register(
                                        nameof(EnableLeftTopOverlay),
                                        typeof(bool),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(Boxing.False));

        public static readonly DependencyProperty EnableRightBottomOverlayProperty =
            DependencyProperty.Register(
                                        nameof(EnableRightBottomOverlay),
                                        typeof(bool),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(Boxing.False));

        public static readonly DependencyProperty AbilityNameProperty =
            DependencyProperty.Register(
                                        nameof(AbilityName),
                                        typeof(string),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(string)));


        public static readonly DependencyProperty RarityLevelProperty =
            DependencyProperty.Register(
                                        nameof(RarityLevel),
                                        typeof(int),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(int)));

        public static readonly DependencyProperty RarityBGProperty =
            DependencyProperty.Register(
                                        nameof(RarityBG),
                                        typeof(string),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(string)));


        public static readonly DependencyProperty KeywordsProperty =
            DependencyProperty.Register(
                                        nameof(Keywords),
                                        typeof(ObservableCollection<ColoredKeyword>),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(ObservableCollection<ColoredKeyword>)));

        public static readonly DependencyProperty VocabulariesProperty =
            DependencyProperty.Register(
                                        nameof(Vocabularies),
                                        typeof(ObservableCollection<ColoredVocabulary>),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(ObservableCollection<ColoredVocabulary>)));

        public static readonly DependencyProperty AvatarProperty =
            DependencyProperty.Register(
                                        nameof(Avatar),
                                        typeof(string),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(string)));

        public static readonly DependencyProperty IntroProperty =
            DependencyProperty.Register(
                                        nameof(Intro),
                                        typeof(string),
                                        typeof(AbilityRenderer),
                                        new PropertyMetadata(default(string)));

        public void SetSize(TemplatedContentSize size)
        {
            Container.Height = size switch
            {
                TemplatedContentSize.Large => 480,
                TemplatedContentSize.Ultra => 720,
                _                          => 320,
            };

            Container.Clip = size switch
            {

                TemplatedContentSize.Large => new RectangleGeometry { RadiusX = 8, RadiusY = 8, Rect = new Rect(0, 0, 480, 480) },
                TemplatedContentSize.Ultra => new RectangleGeometry { RadiusX = 8, RadiusY = 8, Rect = new Rect(0, 0, 480, 720) },
                _                          => new RectangleGeometry { RadiusX = 8, RadiusY = 8, Rect = new Rect(0, 0, 480, 320) },
            };

            ElementalImageBrush.Viewbox = size switch
            {
                TemplatedContentSize.Large => new Rect(-1.625, -1.6, 2.4, 2.4),
                TemplatedContentSize.Ultra => new Rect(-1.02, -1.45, 1.8, 1.8),
                _                          => new Rect(-1.1, -0.7, 1.5, 1.5),
            };
        }


        public ObservableCollection<ColoredVocabulary> Vocabularies
        {
            get => (ObservableCollection<ColoredVocabulary>)GetValue(VocabulariesProperty);
            set => SetValue(VocabulariesProperty, value);
        }

        public ObservableCollection<ColoredKeyword> Keywords
        {
            get => (ObservableCollection<ColoredKeyword>)GetValue(KeywordsProperty);
            set => SetValue(KeywordsProperty, value);
        }

        public string RarityBG
        {
            get => (string)GetValue(RarityBGProperty);
            set => SetValue(RarityBGProperty, value);
        }


        public int RarityLevel
        {
            get => (int)GetValue(RarityLevelProperty);
            set => SetValue(RarityLevelProperty, value);
        }

        public string AbilityName
        {
            get => (string)GetValue(AbilityNameProperty);
            set => SetValue(AbilityNameProperty, value);
        }

        public string Intro
        {
            get => (string)GetValue(IntroProperty);
            set => SetValue(IntroProperty, value);
        }
        public string Avatar
        {
            get => (string)GetValue(AvatarProperty);
            set => SetValue(AvatarProperty, value);
        }

        public bool EnableRightBottomOverlay
        {
            get => (bool)GetValue(EnableRightBottomOverlayProperty);
            set => SetValue(EnableRightBottomOverlayProperty, Boxing.Box(value));
        }


        public bool EnableLeftTopOverlay
        {
            get => (bool)GetValue(EnableLeftTopOverlayProperty);
            set => SetValue(EnableLeftTopOverlayProperty, Boxing.Box(value));
        }

        public bool EnableElement
        {
            get => (bool)GetValue(EnableElementProperty);
            set => SetValue(EnableElementProperty, Boxing.Box(value));
        }

        public string ElementImageID
        {
            get => (string)GetValue(ElementImageIDProperty);
            set => SetValue(ElementImageIDProperty, value);
        }
    }
}